import { FlyGold } from "../../core/anim/FlyGold";
import BaseUI from "../../core/gui/BaseUI";
import { ClassUI } from "../../core/gui/UIDefine";
import UIManage from "../../core/gui/UIManage";
import Tween from "../../core/anim/Tween";
import UIUtils from "../../core/utils/UIUtils";
import { BadgeType } from "../../model/BadgeType";
import { ui } from "../../ui/layaMaxUI";

export default class HomeView extends BaseUI<ui.main.homeSceneUI, string> {

    protected mask: boolean = true;
    protected clickOther: boolean = true;

    constructor() {
        super(ui.main.homeSceneUI, HomeView.GID());
    }


    onInit(): void {
        // this.onClick(this.view, this.onClickT);

    }

    onOpen(): void {
        console.log("open参数：", this.age);
        console.log(this.view.boxContext);

        this.prepare(this.view.imd2, BadgeType.HOMEVIEW);

    }

    onFadeIn(v: ui.main.homeSceneUI): void {
        // let node = v.getChildAt(1) as Laya.Sprite;
        let node = v.boxContext;
        UIUtils.setPivot(node);
        Tween.once(node).set({ scaleX: 0.5, scaleY: 0.5 }).to({ scaleX: 1, scaleY: 1 }, 400, Tween.turnEase(Laya.Ease.backOut))
    }

    onFadeOut(v: ui.main.homeSceneUI) {
        // let node = v.getChildAt(1) as Laya.Sprite;

        return new Promise((resolve, reject) => {
            let node = v.boxContext;
            UIUtils.setPivot(node);
            Tween.once(node).set({ scaleX: 1, scaleY: 1 })
                .to({ scaleX: 0, scaleY: 0 }, 400, Tween.turnEase(Laya.Ease.backOut))
                .call(() => resolve)
        })

    }

    onClose(type?: string): void {
        FlyGold.Instance().clearEff("homeview");
        this.unPrepare(this.view.imd2, BadgeType.TEST2);
    
    }


    onClickT(e: Laya.Event) {
        this.plyaStr([e.stageX, e.stageY])
    }


    private playCoin(start) {
        let fly = FlyGold.Instance();

        fly.flyRes("images/common/coin.png", start, [0, 0], 20, "homeview");
    }

    private plyaStr(start) {
        let fly = FlyGold.Instance();

        // fly.flyRes("images/common/coin.png", start, [0, 0], 20, "coin");
        fly.popRes("images/common/coin.png", start, "金币+1", "popitem");

    }

    // close(type?: string): void {
    //     this.onClosed(type);
    //     UIManage.I.closeUI(HomeView);
    // }

}